<?php
// // 引用数据库连接文件
// 这是更新客户数据的PHP文件
// 引用数据库连接文件
require_once 'databaseConnection.php';

// 连接数据库
try {
    // 连接数据库
    $dbConn = connectToDatabase();
    echo "成功连接到数据库" . PHP_EOL;

    // 获取 Ajax 请求中的数据
    $id = $_POST['id'];
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $occupation = $_POST['occupation'];
    $idType = $_POST['idType'];
    $idNumber = $_POST['idNumber'];
    $address = $_POST['address'];
    $other = $_POST['other'];

    // 更新客户信息
    $query = "UPDATE customers SET name=:name, email=:email, phone=:phone, occupation=:occupation, idType=:idType, idNumber=:idNumber, address=:address, other=:other WHERE customer_id=:id";

    $stmt = $dbConn->prepare($query);
    $stmt->bindParam(':id', $id);
    $stmt->bindParam(':name', $name);
    $stmt->bindParam(':email', $email);
    $stmt->bindParam(':phone', $phone);
    $stmt->bindParam(':occupation', $occupation);
    $stmt->bindParam(':idType', $idType);
    $stmt->bindParam(':idNumber', $idNumber);
    $stmt->bindParam(':address', $address);
    $stmt->bindParam(':other', $other);

    if ($stmt->execute()) {
        echo '客户信息更新成功';
    } else {
        echo '客户信息更新失败';
    }

    // 关闭数据库连接
    $dbConn = null;
} catch (PDOException $e) {
    echo "连接数据库时发生错误: " . $e->getMessage();
}
